import 'dart:async';

import 'package:flutter/material.dart';
import 'package:whale/helper/component/video/video_player_view.dart';

import '../index.dart';

class VideoPlayerListCell extends StatefulWidget {
  const VideoPlayerListCell(this.md, {super.key});
  final VideoModel md;

  @override
  State<VideoPlayerListCell> createState() => _VideoPlayerListCellState();
}

class _VideoPlayerListCellState extends State<VideoPlayerListCell> {
  late final key = GlobalKey();

  @override
  void didUpdateWidget(covariant VideoPlayerListCell oldWidget) {
    widget.md.setupOff(key);
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: [
          VideoPlayerView(
            key: key,
            widget.md.url,
            controller: widget.md.streamController,
          ),
          Text(widget.md.title ?? ''),
        ],
      ),
    );
  }
}
